/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.swirrel.listener;

import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 *
 * @author Gronau
 */
public class SwirrelContainerListener extends AbstractSwirrelListener implements ContainerListener  {

    private final MethodCall componentAddedCall;
    private final MethodCall componentRemovedCall;

    public SwirrelContainerListener(MethodCall componentAddedCall,
            MethodCall componentRemovedCall) {
        this.componentAddedCall = componentAddedCall;
        this.componentRemovedCall = componentRemovedCall;
        if(! checkSignature(componentAddedCall, ContainerEvent.class) ||
            ! checkSignature(componentRemovedCall, ContainerEvent.class)    ) {
            throw new SwirrelException("Method must have none or one ContainerEvent argument");
        }
    }

    public void componentAdded(ContainerEvent e) {
        call(componentAddedCall, e);
    }

    public void componentRemoved(ContainerEvent e) {
         call(componentRemovedCall, e);
    }
}